<template>
  <view class="homePage">
    <view class="list">
      <u-cell-group title="管理信息">
        <u-cell title="资产编号">
          <view slot="value" class="u-slot-value">
            <u-input :border="none" inputAlign="right" placeholder="请输入资产编号" v-model="model.assetsNo"></u-input>
          </view>
        </u-cell>
        <u-cell title="资产名称">
          <view slot="value" class="u-slot-value">
            <u-input inputAlign="right" placeholder="请输入资产名称" :border="none" v-model="model.assetsName"></u-input>
          </view>
        </u-cell>
        <u-cell title="保管单位" isLink @click="addCreate(0)">
          <text slot="value" class="u-slot-value">{{model.depository}}</text>
        </u-cell>
        <u-cell title="购置单位" isLink @click="addCreate(1)">
          <text slot="value" class="u-slot-value">{{model.purchase}}</text>
        </u-cell>
        <u-cell title="使用人" isLink @click="User(0)">
          <text slot="value" class="u-slot-value">{{model.user}}</text>
        </u-cell>
        <u-cell title="管理人" isLink @click="User(1)">
          <text slot="value" class="u-slot-value">{{model.depositary}}</text>
        </u-cell>

        <u-cell title="资产来源" isLink @click="addCreate(2)">
          <text slot="value" class="u-slot-value">{{model.source}}</text>
        </u-cell>
        <u-cell title="取得方式" isLink @click="addCreate(4)">
          <text slot="value" class="u-slot-value">{{model.getMode}}</text>
        </u-cell>
        <!-- 是否盘点 -->
        <u-cell title="是否盘点" isLink @click="addCreate(7)">
          <text slot="value" class="u-slot-value">{{model.inventory}}</text>
        </u-cell>
        <u-cell title="制造厂家">
          <view slot="value" class="u-slot-value">
            <u-input inputAlign="right" placeholder="请输入制造厂家" :border="none" v-model="model.manufactor"></u-input>
          </view>

        </u-cell>

        <u-cell title="资产型号">
          <view slot="value" class="u-slot-value">
            <u-input inputAlign="right" placeholder="请输入资产型号" :border="none" v-model="model.assetsModel"></u-input>
          </view>

        </u-cell>
        <u-cell title="资产形成">
          <view slot="value" class="u-slot-value">
            <u-input inputAlign="right" placeholder="请输入资产形成" :border="none" v-model="model.assetsFormation"></u-input>
          </view>
        </u-cell>

        <!-- 资产价值 -->

        <u-cell title="资产价值">
          <view slot="value" class="u-slot-value">

            <u-input inputAlign="right" placeholder="请输入最小资产价值" :border="none" v-model="model.priceMin" type="number">
            </u-input>
            <u-input inputAlign="right" placeholderStyle="color: #c0c4cc" placeholder="请输入最大资产价值" :border="none" v-model="model.priceMax" type="number"></u-input>
          </view>
        </u-cell>
      </u-cell-group>
      <!-- 分类信息 -->
      <u-cell-group title="分类信息">
        <u-cell title="资产大类" isLink @click="addCreate(6)">
          <text slot="value" class="u-slot-value">{{model.assetsClass}}</text>
        </u-cell>
        <u-cell title="资产小类" isLink @click="AssetClass">
          <text slot="value" class="u-slot-value">{{model.assetsSubclass}}</text>
        </u-cell>

        <u-cell title="资产属性" isLink @click="addCreate(3)">
          <text slot="value" class="u-slot-value">{{model.attribute}}</text>
        </u-cell>

        <u-cell title="资产状态" isLink @click="addCreate(5)">
          <text slot="value" class="u-slot-value">{{model.state }}</text>
        </u-cell>

      </u-cell-group>
      <!-- 日期选择 -->
      <u-cell-group title="登账开始日期-登账结束日期">
        <view style="margin-top: 10upx;">
          <uni-datetime-picker v-model="model.registertDate" type="daterange" rangeSeparator="至" />
        </view>
      </u-cell-group>

      <!-- 取得日期 -->
      <u-cell-group title="取得日期">
        <view style="margin-top: 10upx;">
          <uni-datetime-picker v-model="model.getDate" type="daterange" rangeSeparator="至" />
        </view>
      </u-cell-group>
      <!-- 分类信息 -->
      <u-cell-group title="使用信息">
        <u-cell title="工程项目" isLink @click="addCreate(8)">
          <text slot="value" class="u-slot-value">{{model.engineering}}</text>
        </u-cell>
        <u-cell title="设备等级">
          <view slot="value" class="u-slot-value">
            <u-input inputAlign="right" placeholder="请输入设备等级" :border="none" v-model="model.level"></u-input>
          </view>
        </u-cell>
        <u-cell title="所属系统">
          <view slot="value" class="u-slot-value">
            <u-input inputAlign="right" placeholder="请输入所属系统" :border="none" v-model="model.system"></u-input>
          </view>
        </u-cell>

        <u-cell title="建筑面积">
          <view slot="value" class="u-slot-value">
            <u-input inputAlign="right" placeholder="请输入建筑面积" :border="none" v-model="model.builtupArea" type="number">
            </u-input>
          </view>
        </u-cell>
        <u-cell title="占用面积">
          <view slot="value" class="u-slot-value">
            <u-input inputAlign="right" placeholder="请输入占用面积" :border="none" v-model="model.occupiedArea" type="number">
            </u-input>
          </view>
        </u-cell>

        <!-- 登账人员 -->
        <u-cell title="登账人员" isLink @click="User(2)">
          <text slot="value" class="u-slot-value">{{model.account}}</text>
        </u-cell>

        <!-- 公务用车分类 -->
        <u-cell title="公务用车分类">
          <view slot="value" class="u-slot-value">
            <u-input inputAlign="right" placeholder="请输入公务用车分类" :border="none" v-model="model.busType"></u-input>
          </view>

        </u-cell>

        <!-- 车型 -->
        <u-cell title="车型">
          <view slot="value" class="u-slot-value">
            <u-input inputAlign="right" placeholder="请输入车型" :border="none" v-model="model.vehicleType"></u-input>
          </view>

        </u-cell>

        <!-- 车型 -->
        <u-cell title="存放地">
          <view slot="value" class="u-slot-value">
            <u-input inputAlign="right" placeholder="请输入存放地" :border="none" v-model="model.deposit"></u-input>
          </view>

        </u-cell>
      </u-cell-group>

      <!-- 弹框 -->
      <u-picker @confirm="confirm" @cancel="show=false" :show="show" :columns="columns" keyName="label">
      </u-picker>

      <!-- 基础用法选人 -->
      <template v-if="information.userPlay">
        <u-popup height="90%" mode="bottom" :show="information.userPlay">
          <tree @onchange="onchange" :type='treeType'></tree>
        </u-popup>
      </template>
      <!-- 资产小类 -->

      <u-popup height="90%" mode="bottom" :show="information.selection">
        <selection @onClick="onClick" v-if="information.selection" :assetsClass="information.assetsClass">
        </selection>
      </u-popup>
    </view>
    <!-- 底部 -->
    <view class="footer">
      <u-button size="large" type="primary" text="确定" @click="add"></u-button>
      <u-button size="large" text="重置" @click="cancel"></u-button>
    </view>
  </view>
</template>

<script>
import tree from "./tree/tree.vue"
import selection from "./tree/selection.vue"

export default {
  components: {
    tree,
    selection
  },
  props: {
    modelList: {
      type: Object,

    },
  },

  data() {
    return {
      model: {
        assetsNo: "",
        assetsName: "",
        assetsClass: "",
        assetsSubclass: "", assetsModel: "", assetsFormation: "", manufactor: "", depository: "", purchase: "", user: "", depositary: "", deposit: "", registerStartDate: "", registerEndDate: "", getDateStart: "", getDateEnd: "", priceMax: "", priceMin: "", source: "", attribute: "", getMode: "", account: "", engineering: "", builtupArea: "", occupiedArea: "", busType: "", vehicleType: "", level: "", system: "", inventory: "", state: "", order: { orderParam: "", isAes: false }, pageIndex: 1, pageSize: 10
      },

      // 管理单位
      information: {
        userPlay: false,
        selection: false, //资产小类
      },

      show: false,
      columns: [],
      typeIndex: 0,
      range: [],
      form: {
        deptId: null,
        type: 2
      },
      template: [{
        id: 0,
        label: "全部"
      },
      {
        id: 1,
        label: "已盘点"
      },
      {
        id: 2,
        label: "未盘点"
      }
      ],
      getDate: [], //开始结束日期
      registertDate: [], //取得日期
      showDate: false,
      startTime: {
        start: '',
        end: ''
      },
      userIndex: 0, //选人
      treeType: 0
    };
  },
  onLoad() {
    this.startTime.start = uni.$u.timeFormat(new Date(), 'yyyy-mm-dd');
    this.startTime.end = uni.$u.timeFormat(new Date(), 'yyyy-mm-dd');
  },
  mounted() {

    if (this.modelList) {
      this.model = this.modelList
    }

  },
  methods: {
    // 打开选人
    User(index) {
      this.userIndex = index
      this.treeType = 1
      this.information.userPlay = true
    },
    // 关闭组织架构
    onchange(userName) {
      this.information.userPlay = false
      if (this.userIndex == 0) {
        this.model.user = userName
      } else if (this.userIndex == 1) {
        this.model.depositary = userName
      } else {
        this.model.account = userName
      }
    },
    onClick(user) {
      this.model.assetsSubclass = user
      this.information.selection = false
    },
    // 选择小类
    AssetClass() {
      if (!this.model.assetsClass) return this.$u.toast('请先选择资产大类')
      this.information.selection = true
    },
    addCreate(index) {
      this.show = true
      this.typeIndex = index

      switch (this.typeIndex) {
        case 0:
          this.GetCenterDept()
          break
        case 1:
          this.GetPurchase()
          break
        case 2:
          this.ZCLY()
          break
        case 3:
          this.ZCSX()
          break
        case 4:
          this.QDFS()
          break
        case 5:
          this.ZCZT()
          break
        case 6:
          this.GetClassOption()
          break
        case 7:
          this.templateItem()
          break
        case 8:
          this.engineering()
          break
        default:
          //这里是没有找到对应的值处理
          break
      }

    },
    confirm(e) {

      switch (this.typeIndex) {
        case 0:
          if (e.value[0].id == -1) {
            this.model.depository = ''
          } else {
            this.model.depository = e.value[0].label
          }
          break
        case 1:
          this.model.purchase = e.value[0].label
          break
        case 2:
          this.model.source = e.value[0].label
          break
        case 3:
          this.model.attribute = e.value[0].label
          break
        case 4:
          this.model.getMode = e.value[0].label
          break
        case 5:
          this.model.state = e.value[0].id
          break
        case 6:
          this.model.assetsClass = e.value[0].label
          this.information.assetsClass = e.value[0].id
          break
        case 7:
          this.model.inventory = e.value[0].label
          break
        case 8:
          this.model.engineering = e.value[0].label
          break
        default:
          //这里是没有找到对应的值处理
          break
      }

      this.show = false
    },
    // 保管单位
    GetCenterDept() {
      this.$u.api.GetCenterDept().then((res) => {
        const data = res.data.map((x) => {
          return {
            id: x.objectID,
            label: x.name
          }
        })
        const arr = [{
          label: '部门资产',
          id: -1,
        }]
        this.columns = [arr.concat(data)]

      })
    },
    // 购置单位
    GetPurchase() {
      this.$u.api.GetPurchase().then((res) => {
        const data = res.data.map((x) => {
          return {
            id: x.objectID,
            label: x.name
          }
        })
        this.columns = [data]
      })
    },
    // 资产来源
    ZCLY() {
      this.$u.api.ZCLY().then((res) => {
        const data = res.data.map((x) => {
          return {
            id: x.objectID,
            label: x.val
          }
        })
        this.columns = [data]

      })
    },


    // 资产属性
    ZCSX() {
      this.$u.api.ZCSX().then((res) => {
        const data = res.data.map((x) => {
          return {
            id: x.objectID,
            label: x.val
          }
        })
        this.columns = [data]

      })
    },

    // 取得方式
    QDFS() {
      this.$u.api.QDFS().then((res) => {
        const data = res.data.map((x) => {
          return {
            id: x.objectID,
            label: x.val
          }
        })
        this.columns = [data]

      })
    },
    // 状态
    ZCZT() {
      this.$u.api.ZCZT().then((res) => {
        const data = res.data.map((x) => {
          return {
            id: x.objectID,
            label: x.val
          }
        })
        this.columns = [data]

      })
    },

    // 资产大类
    GetClassOption() {
      this.$u.api.GetClassOption().then((res) => {
        const data = res.data.map((x) => {
          return {
            id: x.objectID,
            label: x.className
          }
        })
        this.columns = [data]

      })
    },



    // 是否盘点
    templateItem() {
      this.columns = [this.template]
    },
    // 工程项目
    engineering() {

      this.$u.api.GetOption().then((res) => {

        const data = res.data.map((x) => {
          return {
            id: x.objectID,
            label: x.projectName
          }
        })
        this.columns = [data]
      })
    },

    // 取消
    cancel() {
      this.model = {
        assetsNo: "",
        assetsName: "",
        assetsClass: "",
        assetsSubclass: "", assetsModel: "", assetsFormation: "", manufactor: "", depository: "", purchase: "", user: "", depositary: "", deposit: "", registerStartDate: "", registerEndDate: "", getDateStart: "", getDateEnd: "", priceMax: "", priceMin: "", source: "", attribute: "", getMode: "", account: "", engineering: "", builtupArea: "", occupiedArea: "", busType: "", vehicleType: "", level: "", system: "", inventory: "", state: "", order: { orderParam: "", isAes: false }, pageIndex: 1, pageSize: 10
      },
        this.$emit('changeClose', '')
    },
    // 确定
    add() {
      this.$emit('change', this.model)
    },
  }
}
</script>

<style lang="scss">
.homePage {
  .footer {
    z-index: 9;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
}
</style>
